package com.stars.services.impl;

import com.stars.common.base.ResultMsg;
import com.stars.common.tree.TreeJson;
import com.stars.services.BaseConfigTreeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by luodajie on 2019/1/5.
 */
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
public abstract class BaseConfigTreeServiceImpl<M extends Mapper<T>, T> extends BaseConfigServiceImpl implements BaseConfigTreeService<T> {

    @Override
    public ResultMsg saveTree(TreeJson treeJson) throws Exception {
        Map<String,String> map = new HashMap<>();
        //添加
        add(treeJson,map);
        //更新
        update(treeJson,map);
        //删除
        if(StringUtils.isNotBlank(treeJson.getDelJson())){
            String [] ids = treeJson.getDelJson().split(",");
           return deleteByIds(ids);
        }
        return ResultMsg.success();
    }

    public abstract void add(TreeJson treeJson, Map<String,String> map) throws Exception;

    public abstract void update(TreeJson treeJson,Map<String,String> map) throws Exception;
}
